package com.leo.apptest.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.leo.apptest.R;

/**
 * Created by zhangguobao on 16/10/13.
 */
public class CommunicateFragment extends Fragment implements View.OnClickListener{
    private View mainView;
    private Button mBtPerform;
    private static final String TAG = "CommunicateFragment";

    public interface FragmentCallback{
        void performClick();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView: ");
        if (mainView == null) {
            System.out.println(container.getParent());
            mainView = inflater.inflate(R.layout.fragment_communicate,container,false);
            initView();
        }
        return mainView;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate: ");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d(TAG, "onDestroyView: ");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy: ");
    }


    private void initView() {
        mBtPerform = (Button) mainView.findViewById(R.id.btPerform);
        mBtPerform.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (getActivity() instanceof FragmentCallback) {
            ((FragmentCallback) getActivity()).performClick();
        }
    }
}
